package com.example.module_word.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.example.module_word.R;
import com.example.module_word.adapter.IndexStackRvAdapter;
import com.example.module_word.data.DanCiData;
import com.example.module_word.databinding.ActivityIndexStackBinding;
import com.example.module_word.listener.LearnOnClickItemListener;
import com.fenghuajueli.libbasecoreui.utils.QuickClickUtils;
import java.util.List;

public class IndexStackActivity extends AppCompatActivity implements View.OnClickListener {
    private ActivityIndexStackBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityIndexStackBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        bindListener();
        binding.indexQbsk.setSelected(true);
        initAdapter(DanCiData.getDanCiKindList());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        binding.indexRv.setLayoutManager(linearLayoutManager);
    }

    private void initAdapter(List<String> list) {
        IndexStackRvAdapter indexStackRvAdapter = new IndexStackRvAdapter(list);
        binding.indexRv.setAdapter(indexStackRvAdapter);
        indexStackRvAdapter.getOnClick(new LearnOnClickItemListener() {
            @Override
            public void onItemClick(String content) {
                if (QuickClickUtils.isFastClick()) {
                    return;
                }
                DanCiData.updateMyStackByKind(false,DanCiData.getMyStackByFlag());
                //将当前修改为选中
                DanCiData.updateMyStackByKind(true,content);
                finish();
            }
        });
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.index_back){
            //返回
            onBackPressed();
        }else if (id == R.id.index_qbsk){
            //全部书库
            initAdapter(DanCiData.getDanCiKindList());
            binding.indexQbsk.setSelected(true);
            binding.indexWdsk.setSelected(false);
            binding.indexQbsk.setTextColor(Color.parseColor("#ff313337"));
            binding.indexWdsk.setTextColor(Color.parseColor("#ABB0BF"));
        }else if (id == R.id.index_wdsk){
            //我的书库
            initAdapter(DanCiData.getMyStack());
            binding.indexQbsk.setSelected(false);
            binding.indexWdsk.setSelected(true);
            binding.indexWdsk.setTextColor(Color.parseColor("#ff313337"));
            binding.indexQbsk.setTextColor(Color.parseColor("#ABB0BF"));
        }
    }

    private void bindListener() {
        binding.indexBack.setOnClickListener(this);
        binding.indexWdsk.setOnClickListener(this);
        binding.indexQbsk.setOnClickListener(this);
    }
}